/********************************************************************************************************
 * @file	ial_stack.h
 *
 * @brief	This is the header file for BLE SDK
 *
 * @author	BLE GROUP
 * @date	2020.06
 *
 * @par     Copyright (c) 2020, Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
 *          All rights reserved.
 *
 *          Redistribution and use in source and binary forms, with or without
 *          modification, are permitted provided that the following conditions are met:
 *
 *              1. Redistributions of source code must retain the above copyright
 *              notice, this list of conditions and the following disclaimer.
 *
 *              2. Unless for usage inside a TELINK integrated circuit, redistributions
 *              in binary form must reproduce the above copyright notice, this list of
 *              conditions and the following disclaimer in the documentation and/or other
 *              materials provided with the distribution.
 *
 *              3. Neither the name of TELINK, nor the names of its contributors may be
 *              used to endorse or promote products derived from this software without
 *              specific prior written permission.
 *
 *              4. This software, with or without modification, must only be used with a
 *              TELINK integrated circuit. All other usages are subject to written permission
 *              from TELINK and different commercial license may apply.
 *
 *              5. Licensee shall be solely responsible for any claim to the extent arising out of or
 *              relating to such deletion(s), modification(s) or alteration(s).
 *
 *          THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 *          ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 *          WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 *          DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER BE LIABLE FOR ANY
 *          DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 *          (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *          LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 *          ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *          (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 *          SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *******************************************************************************************************/
#ifndef IAL_STACK_H_
#define IAL_STACK_H_

#if (LL_FEATURE_ENABLE_ISO)

#include "stack/ble/controller/ll/iso/iso.h"
#include "stack/ble/controller/ll/iso/iso_stack.h"

/******************************* Macro & Enumeration & Structure Definition for Stack Begin, user can not use!!!!  *****/

typedef enum{
	UNFRAMED_START,
	UNFRAMED_CONTINUE,
	UNFRAMED_END,
	UNFRAMED_COMPLETE,
}ll_iso_unframe_type_t;

typedef enum{
	SDU_STATE_NEW,
	SDU_STATE_CONTINUE,
}ll_iso_sdu_unframe_state_t;


typedef struct{
	u8 sc	:1;
	u8 cmplt:1;
	u8 RFU  :6;

	u8 length;

	u32 time_offset:24;
}iso_framed_segmHdr_t;

/***************************
 * iso tx information
 */
typedef struct{
	u16 lastPktSeqNum;   	//HCI packet sequence number
	u16	rsvd;
	u32 lastSduTimestamp;	//HCI timestamp, SDU synchronization reference

	u8  numSduEachCisEvent;
	u8 	sdu_cnt;
	u8  numSdu2Pdu;
	u8	invalid;
}ll_iso_sdu_tx_infor_t;


/************************
 * sdu buff manage
 */
typedef struct{
	u8 *tx_fifo_b;
	u8 *rx_fifo_b;

	u16 tx_fifo_num;
	u16 rx_fifo_num;

	u16 max_tx_size;
	u16 max_rx_size;

}iso_sdu_mng_t;

typedef struct
{
	u8  data_path_direction;
	u8  data_path_id;
	u8 codec_configration_length;
	u8  codec_id[5];

	u32 controller_delay;

	u8	codec_config[32];

}isoal_datapath_para_t;


extern iso_sdu_mng_t sdu_mng;


typedef struct{

	u8 tx_wptr; 	   //tx sdu fifo
	u8 tx_rptr;

	u8 tx_sdu_sn;
	u8 tx_pdu_sn;

}ll_iso_bis_infor_t;


typedef 	void (*iso_cis_establishDatapathCompleteCallback_t)(u16 h);
iso_cis_establishDatapathCompleteCallback_t	iso_cis_establishDatapathCompleteCallback;

extern iso_sdu_mng_t sduCisMng;
extern iso_sdu_mng_t sduBisMng;

/******************************* Stack Interface Begin, user can not use!!! ********************************************/
//int 		blt_ial_maniloop(void);
int	 	blt_ial_cis_mainloop(void);
int 	blt_ial_bisBraocast_mainloop(void);
int 	blt_ial_bisSync_mainloop(void);
int 	blt_ial_isochronous_testMode_mainloop(void);

void 		blt_cis_ial_DataPathEstablishCallback(u16 cis_connHandle);
ble_sts_t 	blt_ial_reassembleCisPdu2Sdu(u16 cis_connHandle, iso_rx_evt_t* pIsoRxEvt);

/******************************* Stack Interface End *******************************************************************/


#endif


#endif
